home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <io.h>
- #include <dos.h>
- #include <bios.h>
- #include "pw.h"
-
- #define ALT_KEY ((*(char far *) (config+0x17)) & 0x8)
-
- struct ListBox { struct NodeHead TextNodeHead;
- unsigned count;
- int pos, displayoffset;
- };
-
- char far *config = (char far *) 0x400000;
- char far *screenptr = (char far *) 0xB8000000;
-
- struct Border BoldBorder = { '╔','╗','╝','╚','║','═' };
- struct Border NormalBorder = { '┌','┐','┘','└','│','─' };
-
- long ButtonProc ( WINDOW *, unsigned,int, long);
- long EditProc ( WINDOW *, unsigned, int, long);
- long ListBoxProc ( WINDOW *, unsigned, int, long);
-
- void (interrupt far *oldTimerProc) ();
- int timerenabled = TRUE, mouse;
- int ExitLoop=FALSE,RetCode;
-
- int AddClass ( char *, long (*)());
-
- struct NodeHead ClassNode;
- struct NodeHead WindowNode;
- struct NodeHead EditNode;
- struct NodeHead TimerNode;
- struct NodeHead NodeListHead;
-
- int menucheck=FALSE;
- int classcount=0;
- int cursorchanged=TRUE;
- int oldcursorpos;
-
- /******************************************************************************/
- /******************************************************************************/
-
- void strrcopy ( char *target, char *source)
- {
- register unsigned i,l;
- for (i=l=strlen(source);i>1;i--) *(target+i) = *(source+i);
- *(target+l) = 0;
- }
-
- /******************************************************************************/
-
- int Clear ( struct Window *Window)
- {
- register unsigned x, y;
-
- for (y=0;y<Window->CRect.height;y++) {
- SetCursor ( Window, 0, y);
- for (x=0;x<Window->CRect.width;x++) OutChar ( Window, ' ');
- }
- }
-
- /******************************************************************************/
-
- void interrupt far TimerProc ( es, ds, di, si, bp, sp, bx, dx, cx, ax, ip, cs, flags)
- unsigned es, ds, di, si, bp, sp, bx, dx, cx, ax, ip, cs, flags;
- {
- static struct TimerInfo *TimerInfo;
- struct Node *Node = TimerNode.FirstNode;
-
- if (timerenabled && (TimerInfo = (struct TimerInfo *) Node->Item)) {
- do {
- if (TimerInfo->Time_to_go) TimerInfo->Time_to_go--;
- Node = Node->NextNode;
- } while (TimerInfo = (struct TimerInfo *) Node->Item);
- }
- _chain_intr ( oldTimerProc);
- }
-
- /******************************************************************************/
-
- void Intr ( unsigned ax, unsigned bx, unsigned cx, unsigned dx)
- {
- union REGS InRegs, OutRegs;
- struct SREGS SegRegs;
-
- segread (&SegRegs);
- InRegs.x.ax = ax;
- InRegs.x.bx = bx;
- InRegs.x.cx = cx;
- InRegs.x.dx = dx;
-
- int86x ( 0x10 ,&InRegs, &OutRegs, &SegRegs);
- }
-
-
- int SetTimer ( struct Window *Window, unsigned time)
- {
- struct TimerInfo *TimerInfo;
-
- if (!(TimerInfo = (struct TimerInfo *) malloc ( sizeof (struct TimerInfo)))) return FALSE;
- TimerInfo->Time = TimerInfo->Time_to_go = time;
- TimerInfo->Window = Window;
- timerenabled = FALSE;
- AddNode ( &TimerNode, (int) TimerInfo);
- timerenabled = TRUE;
- return (int) (TimerInfo);
- }
-
- /******************************************************************************/
-
- int KillTimer ( int Timer)
- {
- timerenabled = FALSE;
- DeleteNode ( &TimerNode, Timer);
- timerenabled = TRUE;
- free ((char *) Timer);
- return TRUE;
- }
-
- /******************************************************************************/
-
- int CheckTimer ()
- {
- static struct TimerInfo *TimerInfo;
- struct Node *Node = TimerNode.FirstNode;
-
- if (!(TimerInfo = (struct TimerInfo *) GetNode ( &TimerNode, 0, GN_FIRST))) return FALSE;
- do {
- if (TimerInfo->Time_to_go) continue;
- SendMessage ( TimerInfo->Window, WM_TIMER, 0, 0L);
- TimerInfo->Time_to_go = TimerInfo->Time;
- } while ( TimerInfo = (struct TimerInfo *) GetNode ( &TimerNode, (int) TimerInfo, GN_NEXT));
- return TRUE;
- }
-
- /******************************************************************************/
-
- int _memcpy ( char far *target, char far *source, unsigned count)
- {
- register unsigned i;
- for (i=0;i<count;i++) *target++ = *source++;
- return 1;
- }
-
- /******************************************************************************/
-
- int ScrollWindow ( struct Window *Window, int rx, int ry)
- {
- register int y, x, in, i;
-
- if (ry==-1) {
- for (y=1;y<=Window->CRect.height;y++)
- for (x=0;x<Window->CRect.width;x++) {
- in = ReadPoint ( Window, x, y);
- SetCursor ( Window, x, y-1);
- OutChar ( Window, (char) in);
- }
- for (x=0;x<Window->CRect.width;x++) {
- SetCursor ( Window, x, Window->CRect.height-1);
- OutChar ( Window, (char) ' ');
- }
- }
-
- if (ry==1) {
- for (y=Window->CRect.height-1;y;y--)
- for (x=0;x<Window->CRect.width;x++) {
- in = ReadPoint ( Window, x, y-1);
- SetCursor ( Window, x, y);
- OutChar ( Window, (char) in);
- }
- for (x=0;x<Window->CRect.width;x++) {
- SetCursor ( Window, x, 0);
- OutChar ( Window, (char) ' ');
- }
- }
-
- if (rx==1) {
- for (y=0;y<Window->CRect.height;y++)
- for (x=0;x<Window->CRect.width-1;x++) {
- in = ReadPoint ( Window, x, y);
- SetCursor ( Window, x+1, y);
- OutChar ( Window, (char) in);
- }
- for (y=0;y<Window->CRect.height;y++) {
- SetCursor ( Window, 0, y);
- OutChar ( Window, (char) ' ');
- }
- }
-
- if (rx==-1) {
- for (y=0;y<Window->CRect.height;y++)
- for (x=1;x<Window->CRect.width;x++) {
- in = ReadPoint ( Window, x, y);
- SetCursor ( Window, x-1, y);
- OutChar ( Window, (char) in);
- }
- for (y=0;y<Window->CRect.height;y++) {
- SetCursor ( Window, Window->CRect.height-1, y);
- OutChar ( Window, (char) ' ');
- }
- }
- }
-
- /******************************************************************************/
-
- int SetCursor ( struct Window *Window, int x, int y)
- {
- Window->xcur = x;
- Window->ycur = y;
- }
-
- /******************************************************************************/
-
- struct Window *IfWindow ( struct Window *Window, int x, int y)
- {
- struct Window *RunWindow = Window;
- while (RunWindow = (struct Window *) GetNode ( &WindowNode, (int) RunWindow, GN_NEXT))
- if (PtInRect( Window->CRect.x+x, Window->CRect.y+y, (struct Rect *) &RunWindow->x)) return RunWindow;
- return 0;
- }
-
- /******************************************************************************/
-
- int PtInRect ( int x, int y, struct Rect *Rect)
- {
- int left = Rect->x,
- right = left + Rect->width,
- top = Rect->y,
- bottom = top + Rect->height;
-
- if (!((x>=left) && (x<right))) return FALSE;
- if (!((y>=top) && (y<bottom))) return FALSE;
- return TRUE;
- }
-
- /******************************************************************************/
-
- int ReadPoint ( struct Window *Window , int x, int y)
- {
- int far *scrpos, *mempos=0;
- struct Window *RunWindow = Window;
- int xpos, ypos;
-
- if (!PtInRect ( Window->CRect.x+x, Window->CRect.y+y, (struct Rect *) &Window->CRect)) return -1;
-
- while (RunWindow = (struct Window *) GetNode ( &WindowNode, (int) RunWindow, GN_NEXT))
- if (PtInRect( Window->CRect.x+x, Window->CRect.y+y, (struct Rect *) &RunWindow->x)) {
- xpos = (Window->CRect.x+x) - RunWindow->x;
- ypos = (Window->CRect.y+y) - RunWindow->y;
- mempos = (int *) ((RunWindow->buffer + (ypos*((RunWindow->width)*2)) + (xpos*2)));
- return *mempos;
- break;
- }
- if (!mempos) {
- scrpos = (int far *) (screenptr + Window->CRect.x*2 + Window->CRect.y*160 + x*2 + y*160);
- return *scrpos;
- }
- }
-
- /******************************************************************************/
-
- int OutChar ( struct Window *Window ,char out)
- {
- char far *scrpos, *mempos=0;
- struct Window *RunWindow = Window;
- int x, y;
-
- if (!PtInRect ( Window->CRect.x+Window->xcur, Window->CRect.y+Window->ycur, (struct Rect *) &Window->CRect)) return FALSE;
-
- while (RunWindow = (struct Window *) GetNode ( &WindowNode, (int) RunWindow, GN_NEXT))
- if (PtInRect( Window->CRect.x+Window->xcur, Window->CRect.y+Window->ycur, (struct Rect *) &RunWindow->x)) {
- x = (Window->CRect.x+Window->xcur) - RunWindow->x;
- y = (Window->CRect.y+Window->ycur) - RunWindow->y;
- mempos = (RunWindow->buffer + (y*((RunWindow->width)*2)) + (x*2));
- *mempos = out;
- *++mempos = Window->textcolor;
- break;
- }
- if (!mempos) {
- scrpos = (char far *) (screenptr + Window->CRect.x*2 + Window->CRect.y*160 + Window->xcur*2 + Window->ycur*160);
- *scrpos = out;
- *++scrpos = Window->textcolor;
- }
- Window->xcur++;
- cursorchanged = TRUE;
- return out;
- }
-
- /******************************************************************************/
-
- int OutText ( struct Window *Window, int x, int y, char *text, int count)
- {
- SetCursor ( Window, x, y);
- while ( *text && count--) OutChar ( Window, *text++);
- return 1;
- }
-
- int Text ( struct Window *Window, char *text)
- {
- while ( *text) OutChar ( Window, *text++);
- return 1;
- }
-
- /******************************************************************************/
-
- int SetBCursor ( struct Window *Window)
- {
- unsigned x, y;
- x = Window->CRect.x + Window->xcur;
- y = Window->CRect.y + Window->ycur;
- if ( IfWindow (Window, x, y)) x = y = 0;
- Intr ( 0x0200, 0, 0, x | y<<8);
- }
-
- /******************************************************************************/
-
- int InitClass ()
- {
- static char *button = "button",
- *edit = "edit",
- *listbox = "listbox";
- struct Class *Class;
-
- if (!(Class = (struct Class *) malloc (sizeof(struct Class)))) return FALSE;
- strcpy (Class->classname, button);
- Class->function = ButtonProc;
- AddNode ( &ClassNode, (int) Class);
- classcount = 1;
-
- AddClass ( edit, EditProc);
- AddClass ( listbox, ListBoxProc);
- return TRUE;
- }
-
- /******************************************************************************/
-
- int AddClass ( char *name, long (*function)())
- {
- struct Class *Class;
-
- if (!function || !name[0]) return FALSE;
- if (!(Class = (struct Class *) malloc (sizeof(struct Class)))) return FALSE;
- strcpy ( Class->classname, name);
- Class->function = function;
- AddNode ( &ClassNode, (int) Class);
- return ++classcount;
- }
-
- /******************************************************************************/
-
- void InitAll ()
- {
- union REGS InRegs, OutRegs;
- InitClass ();
-
- oldTimerProc = _dos_getvect ( DOSTIMER);
- _dos_setvect ( DOSTIMER, TimerProc);
-
- InRegs.x.ax = 0x0300;
- InRegs.x.bx = 0;
- int86 ( 0x10 ,&InRegs, &OutRegs);
- oldcursorpos = OutRegs.x.dx;
- }
-
- /******************************************************************************/
-
- void CloseAll ()
- {
- union REGS InRegs, OutRegs;
-
- _dos_setvect ( DOSTIMER, oldTimerProc);
-
- InRegs.x.ax = 0x0200;
- InRegs.x.bx = 0;
- InRegs.x.dx = oldcursorpos;
- int86 ( 0x10 ,&InRegs, &OutRegs);
- }
-
- /******************************************************************************/
-
- int SendMessage ( struct Window *Window, unsigned Message, int wParam, long lParam)
- {
- if ( !Window) return -1;
- return (*Window->function)( Window, Message, wParam, lParam);
- }
-
- /******************************************************************************/
-
- int GetClientRect ( struct Window *Window, struct Rect *Rect)
- {
- Rect->x = Rect->y = 0;
- Rect->width = Window->CRect.width;
- Rect->height = Window->CRect.height;
- return TRUE;
- }
-
- /******************************************************************************/
-
- int DestroyWindow ( struct Window *Window)
- {
- register int i;
- register int far *scrpos;
-
- if ( !Window) return FALSE;
- SendMessage ( Window, WM_DESTROY, 0, 0L);
- for (i=0;i<Window->height;i++)
- _memcpy ((char far *) screenptr+Window->y*160+Window->x*2+i*160, (char far *) Window->buffer+i*Window->width*2, Window->width*2);
- free ( Window->buffer);
- DeleteNode ( &WindowNode, (int) Window);
- if (Window->MainWindow) DeleteNode ( &(Window->MainWindow->ChildNode), (int) Window);
- free ( Window);
- return TRUE;
- }
-
- /******************************************************************************/
-
- void SetWindowColor ( struct Window *Window, unsigned color)
- {
- register unsigned x, y, xcur, ycur;
- char in;
- xcur = Window->xcur;
- ycur = Window->ycur;
- Window->textcolor = color;
- for (y=0;y<Window->height;y++) {
- SetCursor ( Window, 0, y);
- for (x=0;x<Window->width;x++) {
- in = ReadPoint ( Window, x, y);
- OutChar ( Window, in);
- }
- }
- Window->xcur = xcur;
- Window->ycur = ycur;
- SetCursor ( Window ,xcur, ycur);
- }
-
- /******************************************************************************/
-
- int AddMenu ( struct Window *Window, struct Menu *Menu)
- {
- if ( Window->y!=Window->CRect.y) {
- Window->CRect.y++;
- Window->CRect.height--;
- }
- ((struct Menu *) Window->addinf) = Menu;
- DrawMenubar ( Window);
- return 1;
- }
-
- /******************************************************************************/
-
- int DrawMenubar ( struct Window *Window)
- {
- unsigned ypos=Window->CRect.y,
- color=Window->color, i;
- struct Menu *RunMenu = (struct Menu *) Window->addinf;
-
- Window->CRect.y = Window->y;
- Window->textcolor = ((struct Menu *) Window->addinf)->color;
- SetCursor ( Window, 0, 0);
- while ( RunMenu) {
- OutChar ( Window, ' ');
- Text ( Window, RunMenu->title);
- OutChar ( Window, ' ');
- RunMenu = RunMenu->NextMenu;
- }
- for (i=Window->xcur;i<Window->width;i++) OutChar ( Window, ' ');
- Window->CRect.y = ypos;
- Window->textcolor = color;
- return TRUE;
- }
-
- /******************************************************************************/
-
- int ShowWindow ( struct Window *Window)
- {
- int memsize;
- int i;
- register int far *scrpos, x, bground;
-
- if ( Window->buffer) free ( Window->buffer);
- memsize = Window->width*2 * Window->height;
- if (!(Window->buffer=(char *) malloc ( memsize))) return FALSE;
- bground = (Window->color << 8) + 0x20;
- for (i=0;i<Window->height;i++) {
- _memcpy ( (char far *) Window->buffer+i*Window->width*2,
- (char far *) scrpos = (char far *) (screenptr+Window->y*160+Window->x*2+i*160), Window->width*2);
- for (x=0;x<Window->width;x++) *scrpos++ = bground;
- }
- return TRUE;
- }
-
- /******************************************************************************/
-
- int UpdateWindow ( struct Window *Window)
- {
- register unsigned i;
- register char far *lo = screenptr + Window->x*2 + Window->y*160;
- struct Border *bord;
-
- if (Window->style & (WNDSTYLE_BORDER|WNDSTYLE_BOLDBORDER)) {
- if ( Window->style & WNDSTYLE_BORDER) bord = &NormalBorder;
- else bord = &BoldBorder;
- *(lo) = bord->nw;
- *(lo + Window->width*2 - 2) = bord->ne;
- *(lo + Window->height*160 - 160) = bord->sw;
- *(lo + Window->height*160 + Window->width*2 - 162) = bord->se;
- for (i=0;i<Window->width-2;i++) {
- *(lo + i*2 + 2) = bord->horz;
- *(lo + i*2 + Window->height*160 -158) = bord->horz;
- }
- for (i=0;i<Window->height-2;i++) {
- *(lo + i*160 + 160) = bord->vert;
- *(lo + i*160 + Window->width*2 + 160 - 2) = bord->vert;
- }
- }
- return TRUE;
- }
-
- /******************************************************************************/
-
- int ShowText ( struct Window *Window)
- {
- char *text = (char *) ((struct Edit *) Window->addinf)->text + ((struct Edit *) Window->addinf)->curpos - Window->xcur;
- int curpos = Window->xcur;
-
- OutText ( Window, 0, 0, text, Window->width);
- OutChar ( Window, ' ');
- Window->xcur = curpos;
- return TRUE;
- }
-
- /******************************************************************************/
-
- struct Window *CreateWindow ( struct NewWindow *NewWindow)
- {
- struct Window *Window;
- unsigned i=0, a=0;
- struct Class *Class = (struct Class *) GetNode ( &ClassNode, 0, GN_FIRST);
-
- if (!(Window = (struct Window *) (char *) malloc (sizeof(struct Window)))) return FALSE;
-
- while ( Class) {
- if (!strcmp(Class->classname,NewWindow->class)) break;
- Class = (struct Class *) GetNode ( &ClassNode, (int) Class, GN_NEXT);
- i++;
- }
-
- if (i==classcount) return FALSE;
- Window->function = Class->function;
- memcpy ( &Window->x, &NewWindow->x, 18);
- Window->name = NewWindow->name;
- Window->buffer = NULL;
- Window->xcur = Window->ycur = 0;
- if (Window->style & (WNDSTYLE_BORDER | WNDSTYLE_BOLDBORDER)) a=1;
- Window->CRect.x = Window->x+a;
- Window->CRect.y = Window->y+a;
- Window->CRect.width = Window->width-2*a;
- Window->CRect.height = Window->height-2*a;
-
- memset ( &Window->ChildNode, 0, sizeof (struct NodeHead));
- if ( Window->MainWindow=NewWindow->MainWindow) AddNode ( &Window->MainWindow->ChildNode, (int) Window);
- AddNode ( &WindowNode, (int) Window);
-
- ShowWindow ( Window);
- UpdateWindow ( Window);
- SendMessage ( Window, WM_CREATE, 0, 0L);
- SendMessage ( Window, WM_PAINT, 0, 0L);
- return Window;
- }
-
- /******************************************************************************/
-
- struct Window *CheckMouse ( unsigned far *x, unsigned far *y)
- {
- struct Window *RunWindow = (struct Window *) GetNode ( &WindowNode, 0, GN_LAST);
- *x /= 8; *y /= 8;
- do {
- if ( PtInRect ( *x, *y, (struct Rect *) &RunWindow->x)) {
- if ( !PtInRect ( *x, *y, (struct Rect *) &RunWindow->CRect)) {
- /* MoveWindow ( RunWindow); */
- break;
- }
- *x -= RunWindow->x;
- *y -= RunWindow->y;
- return RunWindow;
- }
- } while (RunWindow = (struct Window *) GetNode (&WindowNode, (int) RunWindow, GN_PREV));
- return 0;
- }
-
- /******************************************************************************/
-
- int BringWindowtoTop ( struct Window *Window)
- {
- /* PutBackground ( Window); */
- }
-
- /******************************************************************************/
-
- void ExitMainLoop (int Code)
- {
- RetCode = Code;
- ExitLoop = TRUE;
- }
-
- /******************************************************************************/
-
- int MainWindowProc ()
- {
- char in, zero;
- struct Window *Window = (struct Window *) GetNode ( &WindowNode, 0, GN_LAST);
- struct Window *InputWindow, *win, *winbak;
- unsigned far *x, far *y, far *buttons, message, prevbutton=0, stat=FALSE;
-
- /* if (mouse=MOUSEINSTALLED ()) MOUSESHOW (); */
-
- if ( Window->MainWindow) {
- Window = Window->MainWindow;
- InputWindow = (struct Window *) GetNode ( &Window->ChildNode, 0, GN_FIRST);
- }
- else InputWindow = Window;
-
- while (TRUE) {
- if ( cursorchanged) { SetBCursor ( InputWindow); cursorchanged = FALSE; }
- message = 0;
- do {
- if (ExitLoop) {
- ExitLoop = FALSE;
- return RetCode;
- }
- CheckTimer ();
- if ( mouse) {
- /* MOUSEPOSITION ( y, x, buttons); */
- if ( prevbutton - *buttons) {
- prevbutton = *buttons;
- if (stat ^= TRUE) {
- message = WM_LBUTTON;
- if (winbak=CheckMouse ( x, y))
- InputWindow = winbak;
- }
- else message = WM_LBUTTONUP;
- break;
- }
- }
- if (ALT_KEY) {
- while (ALT_KEY);
- menucheck ^= TRUE;
- /* CheckMenu (InputWindow); */
- }
- } while (!kbhit());
- if (!message) {
- in = getch();
- if(!in) { in = getch (); zero = TRUE; }
- else zero = FALSE;
- message = WM_KEYPRESSED;
- }
- else {
- in = 0;
- zero = MAKELONG (*x,*y);
- }
- if (SendMessage (InputWindow, message, (char) in, (long) zero )) continue;
- switch ( in) {
- case 27:
- /* if (mouse) MOUSEHIDE (); */
- return 0; break;
- case 9:
- if (!(win = (struct Window *) GetNode ( &Window->ChildNode, (int) InputWindow, GN_NEXT))) {
- if (!(win = (struct Window *) GetNode ( &Window->ChildNode, 0, GN_FIRST))) break;
- }
- InputWindow = win;
- break;
- }
- }
- }
-
- /******************************************************************************/
-
- long ButtonProc ( WINDOW *Window, unsigned Message, int wParam, long Param)
- {
- static int TimerInfo;
-
- switch (Message) {
- case WM_CREATE:
- Window->addinf = FALSE;
- break;
-
- case WM_PAINT:
- OutText ( Window, 0, 0, Window->name, strlen ( Window->name));
- break;
-
- case WM_LBUTTON:
- if ( Window->addinf) break;
- /* if ( mouse) MOUSEHIDE (); */
- SetWindowColor ( Window, ~Window->color);
- Window->addinf = (char *) 1;
- break;
-
- case WM_LBUTTONUP:
- SetWindowColor ( Window, Window->color);
- Window->addinf = FALSE;
- SendMessage ( Window->MainWindow, WM_COMMAND, Window->ID, 0L);
- /* if (mouse) MOUSESHOW (); */
- break;
-
- default: return FALSE;
- }
- return TRUE;
- }
-
- /******************************************************************************/
-
- long EditProc ( WINDOW *Window, unsigned Message, int wParam, long Param)
- {
- struct Edit Edit;
- int len;
-
- switch ( Message) {
- case WM_DESTROY:
- free ( Window->addinf);
- break;
-
- case WM_CREATE:
- Window->addinf = (char *) malloc (sizeof (struct Edit));
- ((struct Edit *) Window->addinf)->text = (char *) malloc (((struct Edit *) Window->addinf)->memsize = 32);
- *((struct Edit *) Window->addinf)->text = 0;
- ((struct Edit *) Window->addinf)->pos = 0;
- ((struct Edit *) Window->addinf)->curpos = 0;
- ((struct Edit *) Window->addinf)->maxlen = 64;
- break;
-
- case WM_PAINT:
- ShowText ( Window);
- break;
-
- case EC_SETTEXT:
- strcpy ( ((struct Edit *) Window->addinf)->text, (char *) wParam);
- ((struct Edit *) Window->addinf)->pos = 0;
- ((struct Edit *) Window->addinf)->curpos = 0;
- Clear ( Window);
- break;
-
- case EC_GETTEXT:
- strcpy ( (char *) wParam ,((struct Edit *) Window->addinf)->text);
- break;
-
- case EC_SETTEXTMAX:
- ((struct Edit *) Window->addinf)->maxlen = wParam;
- break;
-
- case EC_CLEAR:
- *(((struct Edit *) Window->addinf)->text) = 0;
- Clear ( Window);
- break;
-
- case WM_KEYPRESSED:
- len = strlen (((struct Edit *) Window->addinf)->text);
- if (Param) {
- switch ( wParam) {
- case 83:
- if (((struct Edit *) Window->addinf)->curpos==len) break;
- strcpy ( ((struct Edit *) Window->addinf)->text + ((struct Edit *) Window->addinf)->curpos, ((struct Edit *) Window->addinf)->text + ((struct Edit *) Window->addinf)->curpos+1);
- break;
-
- case 75:
- if (((struct Edit *) Window->addinf)->curpos) {
- if ( Window->xcur) Window->xcur--;
- ((struct Edit *) Window->addinf)->curpos--;
- }
- break;
- case 77:
- if (((struct Edit *) Window->addinf)->curpos==len) break;
- if (Window->xcur<Window->width-1) Window->xcur++;
- ((struct Edit *) Window->addinf)->curpos++;
- break;
- }
- ShowText ( Window);
- }
- else
- switch ((int) (wParam)) {
- case 8:
- if (((struct Edit *) Window->addinf)->curpos==((struct Edit *) Window->addinf)->maxlen) break;
- if (!len || !((struct Edit *) Window->addinf)->curpos) break;
- if (*(((struct Edit *) Window->addinf)->text + ((struct Edit *) Window->addinf)->curpos) == 0) {
- *(((struct Edit *) Window->addinf)->text + ((struct Edit *) Window->addinf)->curpos-1) = '\0';
- }
- else strcpy ( ((struct Edit *) Window->addinf)->text + ((struct Edit *) Window->addinf)->curpos - 1, ((struct Edit *) Window->addinf)->text + ((struct Edit *) Window->addinf)->curpos);
- ((struct Edit *) Window->addinf)->curpos--;
- if (Window->xcur) Window->xcur--;
- else { if (len<Window->width/2)
- Window->xcur = len-2;
- else Window->xcur = Window->width/2;
- }
- ShowText ( Window);
- break;
-
- default:
- if ((wParam<32)||(wParam>127)) return FALSE;
- if (len+1==((struct Edit *) Window->addinf)->maxlen) break;
- if (len==((struct Edit *) Window->addinf)->memsize-2)
- ((struct Edit *) Window->addinf)->text = (char *) realloc ( ((struct Edit *) Window->addinf)->text, ((struct Edit *) Window->addinf)->memsize += 16);
- if ( (*((struct Edit *) Window->addinf)->text+((struct Edit *) Window->addinf)->curpos) == 0) sprintf ( ((struct Edit *) Window->addinf)->text, "%s%c\0", ((struct Edit *) Window->addinf)->text, (char) wParam);
- else { strrcopy ( ((struct Edit *) Window->addinf)->text + ((struct Edit *) Window->addinf)->curpos + 1, ((struct Edit *) Window->addinf)->text + ((struct Edit *) Window->addinf)->curpos);
- *(((struct Edit *) Window->addinf)->text + ((struct Edit *) Window->addinf)->curpos) = (char) wParam;
- *(((struct Edit *) Window->addinf)->text + ((struct Edit *) Window->addinf)->curpos+len) = 0;
- }
- ((struct Edit *) Window->addinf)->curpos++;
- if ( Window->xcur+2 < Window->width) Window->xcur++;
- ShowText ( Window);
- }
- break;
- default: return FALSE;
- }
- return TRUE;
- }
-
- /******************************************************************************/
-
- long ListBoxProc ( WINDOW *Window, unsigned Message, int wParam, long Param)
- {
- struct ListBox *lBox;
- char *text;
- int i;
-
- switch (Message) {
- case WM_CREATE:
- Window->addinf = (char *) malloc (sizeof(struct ListBox));
- memset (Window->addinf,0,sizeof(struct ListBox));
- lBox->count = lBox->pos = lBox->displayoffset = 0;
- AddNode (&NodeListHead,(int) Window);
- break;
-
- case WM_KEYPRESSED:
- if (!(lBox = (struct ListBox *) Window->addinf)) break;
- switch (wParam) {
- case 72:
- if (!lBox->displayoffset) break;
- lBox->displayoffset--;
- ScrollWindow ( Window, 0,1);
- for (i=0,text=(char *) GetNode(&lBox->TextNodeHead,0,GN_FIRST);i<lBox->displayoffset;i++,text=(char *) GetNode(&lBox->TextNodeHead,(int) text,GN_NEXT))
- OutText ( Window, 0, 0, text, Window->width);
- break;
- case 80:
- if (lBox->displayoffset+lBox->pos == Window->height) break;
- ScrollWindow ( Window, 0,-1);
- for (i=0,text=(char *) GetNode(&lBox->TextNodeHead,0,GN_FIRST);i<(lBox->displayoffset+lBox->pos);i++,text=(char *) GetNode(&lBox->TextNodeHead,(int) text,GN_NEXT))
- OutText ( Window, 0, 0, text, Window->width);
- break;
- default: return FALSE;
- }
- break;
-
- case LB_ADDTEXT:
- if (!(lBox = (struct ListBox *) Window->addinf)) break;
- AddNode (&lBox->TextNodeHead,wParam);
- lBox->count++;
- SendMessage (Window,WM_PAINT,0,0L);
- break;
-
- case WM_PAINT:
- if (!(lBox = (struct ListBox *) Window->addinf)) break;
- for (i=0,text=(char *) GetNode(&lBox->TextNodeHead,0,GN_FIRST);text;text=(char *) GetNode(&lBox->TextNodeHead,(int) text,GN_NEXT),i++) {
- if ((i<lBox->displayoffset) || (i>Window->height)) continue;
- OutText ( Window, 0, i-lBox->displayoffset, text, Window->width);
- }
- break;
-
- default: return FALSE;
- }
- return TRUE;
- }
-
- /******************************************************************************/
-
- main ()
- {
- InitAll ();
- WinMain ();
- CloseAll ();
- }
-